package com.wwj.study.interview.chapter2;

import java.io.*;

public class SerializableTest {
    public static void main(String[] args) throws IOException, ClassNotFoundException {
        Order order=new Order();
        order.setOrderId(1);
        order.setOrderCode("1000");

        Member member=new Member();
        member.setId(1);
        member.setName("wwj");
        order.setMember(member);

        ByteArrayOutputStream byteArrayOutputStream =new ByteArrayOutputStream();
        ObjectOutputStream outputStream=new ObjectOutputStream(byteArrayOutputStream);
        outputStream.writeObject(order);
        byte[] bytes= byteArrayOutputStream.toByteArray() ;

        ByteArrayInputStream byteArrayInputStream = new ByteArrayInputStream(bytes);
        ObjectInputStream inputStream=new ObjectInputStream(byteArrayInputStream);
        Order order1= (Order) inputStream.readObject();
        order1.getMember().setName("zhangsan");

        System.out.println(order);
        System.out.println(order1);
    }
}
